/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.app.user.service;

import java.util.List;

import javax.validation.constraints.NotBlank;

import org.hibernate.validator.constraints.Length;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.lang.StringUtils;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.app.user.entity.AppUser;
import com.jeesite.modules.app.user.dao.AppUserDao;
import com.jeesite.modules.file.utils.FileUploadUtils;

/**
 * 用户表Service
 * @author zpp
 * @version 2020-01-23
 */
@Service
@Transactional(readOnly=true)
public class AppUserService extends CrudService<AppUserDao, AppUser> {
	
	/**
	 * 获取单条数据
	 * @param appUser
	 * @return
	 */
	@Override
	public AppUser get(AppUser appUser) {
		return super.get(appUser);
	}
	
	/**
	 * 查询分页数据
	 * @param appUser 查询条件
	 * @param appUser.page 分页对象
	 * @return
	 */
	@Override
	public Page<AppUser> findPage(AppUser appUser) {
		return super.findPage(appUser);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param appUser
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(AppUser appUser) {
		String loginCode = appUser.getLoginCode();
		if(StringUtils.isBlank(loginCode)){
			appUser.setLoginCode(appUser.getMobile());
		}
		super.save(appUser);
		// 保存上传图片
		FileUploadUtils.saveFileUpload(appUser.getId(), "appUser_image");
		// 保存上传附件
		FileUploadUtils.saveFileUpload(appUser.getId(), "appUser_file");
	}
	
	/**
	 * 更新状态
	 * @param appUser
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(AppUser appUser) {
		super.updateStatus(appUser);
	}
	
	/**
	 * 删除数据
	 * @param appUser
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(AppUser appUser) {
		super.delete(appUser);
	}
	
}